import numpy as np
import matplotlib.pyplot as plt

def trigger_idx(trig_arr):
    start_index=[]


    slice_idxs=[]

    for i in range(trig_arr.shape[0]):
        if i+1<trig_arr.shape[0]:
            if abs(trig_arr[i+1]-trig_arr[i])<50 and trig_arr[i]>3000:
                slice_idxs.append(i)

    start_index.append(slice_idxs[0])
    for i in range(len(slice_idxs)):
        if i+1<len(slice_idxs):
            if slice_idxs[i+1]-slice_idxs[i]>1:
                start_index.append(slice_idxs[i+1])
    # print(start_index)


    start_index=np.array(start_index)
    return start_index


trig_url=r"D:\MLDSA_RISCV\traces_trig.npy"

trigger=np.load(trig_url)
trigger=np.mean(trigger,axis=0)
idx=trigger_idx(trigger)
print((idx))
np.save(r"submit_code\start_idx_10.npy",idx)